package HUMAN;

import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.table.TableColumn;

import TOOLS.messageTool;
import VIEWS.v_TableInPanel;

@SuppressWarnings("serial")
public class v_skillListViewer extends v_TableInPanel {
	public JLabel Rcount = new JLabel("结果集=" + 0);
	boolean isSingleSelection = true;

	public JButton buttonList = new JButton("<html>未完<BR>成清单</html>");
	messageTool mt = new messageTool();
	
	int iWIDTH=-1;
	int iHEIGHT=-1;
	
	public static void main(String[] args) throws Exception {
		JFrame jf=new JFrame();
		v_skillListViewer p=new v_skillListViewer();
		jf.setSize(p.getWidth()+20, p.getHeight()+50);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//        jf.addWindowListener(new WindowAdapter() { 
//            public void windowClosing(WindowEvent we) { 
//            	//TODO 关闭窗口时触发
//            } 
//        });
		jf.add(p);
		jf.setLayout(null);
		jf.setTitle("个人技能列表");
		jf.setVisible(true);
	}
	
	public JScrollPane scp02 = new JScrollPane();
	public JTable tab02 = new JTable() {
		/**
		 * 
		 */
		private static final long serialVersionUID = -5995834408990676010L;

		public boolean isCellEditable(int row, int column) {
			return isCellEditable;// 表格不允许被编辑
		}
	};
	
	public JScrollPane scp03 = new JScrollPane();
	public JTable tab03 = new JTable() {
		/**
		 * 
		 */
		private static final long serialVersionUID = -5995834408990676010L;

		public boolean isCellEditable(int row, int column) {
			return isCellEditable;// 表格不允许被编辑
		}
	};

	public v_skillListViewer() {
		myRepaint1();
	}
	
	public v_skillListViewer(JPanel jf) {
		this.iWIDTH=jf.getWidth();
		this.iHEIGHT=jf.getHeight();
		myRepaint1();
	}

	public void setTable1(JTable iTab) {
		tab01 = new JTable() {
			/**
			 * 
			 */
			private static final long serialVersionUID = -5995834408990676010L;

			public boolean isCellEditable(int row, int column) {
				return isCellEditable;// 表格不允许被编辑
			}
		};
		if (iTab == null) {
			tab01.removeAll();
			scp01.getViewport().removeAll();
		} else {
			tab01.setModel(iTab.getModel());
			iTab.setAutoCreateRowSorter(true);
//			tab01.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			tab01.setRowSorter(iTab.getRowSorter());
			tab01.getColumnModel().getColumn(1).setPreferredWidth(50);
			tab01.getColumnModel().getColumn(2).setPreferredWidth(50);
			tab01.getColumnModel().getColumn(3).setPreferredWidth(100);
			tab01.getColumnModel().getColumn(4).setPreferredWidth(50);
			hideCol(tab01,0);
			scp01.getViewport().add(tab01);
			tab01.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			
			
		}
	}
	
	public void setTable2(JTable iTab) {
		tab02 = new JTable() {
			/**
			 * 
			 */
			private static final long serialVersionUID = -5995834408990676010L;

			public boolean isCellEditable(int row, int column) {
				return isCellEditable;// 表格不允许被编辑
			}
		};
		if (iTab == null) {
			tab02.removeAll();
			scp02.getViewport().removeAll();
		} else {
			tab02.setModel(iTab.getModel());
			iTab.setAutoCreateRowSorter(true);
//			tab02.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			tab02.setRowSorter(iTab.getRowSorter());
			tab02.getColumnModel().getColumn(1).setPreferredWidth(100);
			tab02.getColumnModel().getColumn(2).setPreferredWidth(50);
			tab02.getColumnModel().getColumn(3).setPreferredWidth(50);
			tab02.getColumnModel().getColumn(4).setPreferredWidth(100);
			tab02.getColumnModel().getColumn(5).setPreferredWidth(50);
			hideCol(tab02,0);
			scp02.getViewport().add(tab02);
			tab02.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
			
		}
	}
	
	public void setTable3(JTable iTab) {
		tab03 = new JTable() {
			/**
			 * 
			 */
			private static final long serialVersionUID = -5995834408990676010L;

			public boolean isCellEditable(int row, int column) {
				return isCellEditable;// 表格不允许被编辑
			}
		};
		if (iTab == null) {
			tab03.removeAll();
			scp03.getViewport().removeAll();
		} else {
			tab03.setModel(iTab.getModel());
			iTab.setAutoCreateRowSorter(true);
//			tab03.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			tab03.setRowSorter(iTab.getRowSorter());
			tab03.getColumnModel().getColumn(0).setPreferredWidth(50);
			tab03.getColumnModel().getColumn(2).setPreferredWidth(50);
			tab03.getColumnModel().getColumn(4).setPreferredWidth(100);
			tab03.getColumnModel().getColumn(5).setPreferredWidth(50);
			tab03.getColumnModel().getColumn(6).setPreferredWidth(50);
			tab03.getColumnModel().getColumn(7).setPreferredWidth(100);
			hideCol(tab03,1);
			hideCol(tab03,3);
			scp03.getViewport().add(tab03);
			tab03.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
			
		}
	}
	
	public void hideCol(JTable inTab,int hideIndex) {
		TableColumn idColumn= inTab.getColumnModel().getColumn(hideIndex);
		idColumn.setWidth(0);
		idColumn.setMaxWidth(0);
		idColumn.setMinWidth(0);
		inTab.getTableHeader().getColumnModel().getColumn(hideIndex).setMaxWidth(0); //设置表的标题的宽度也为0,这个很重要
		inTab.getTableHeader().getColumnModel().getColumn(hideIndex).setMinWidth(0);
	}

	public void myRepaint1() {
		int sw = Toolkit.getDefaultToolkit().getScreenSize().width;
		int sh = Toolkit.getDefaultToolkit().getScreenSize().height;
		WIDTH = (int) (sw * 0.8);
		this.HEIGHT = (int) (sh * 0.8);
		if(iWIDTH>0) {
			WIDTH=iWIDTH;
		}
		if(iHEIGHT>0) {
			HEIGHT=iHEIGHT;
		}
		buttonWid = 5 * fieldsHei;
		this.columns = 3;
		super.myRepaint();
		this.labels[0].setText("工号: ");
		this.labels[1].setText("名称: ");
		this.labels[2].setText("班别: ");

		this.buttonAdd.setText("新增");
		this.buttonAdd.setEnabled(false);
		this.buttonAdd.setVisible(false);
		this.buttonSave.setText("保存");
		this.buttonSave.setEnabled(false);
		this.buttonSave.setVisible(false);
		this.buttonDelete.setEnabled(false);
		this.buttonDelete.setVisible(false);
		this.buttonEdit.setText("<html>培训报名</html>");
		this.buttonEdit.setEnabled(false);
		this.buttonEdit.setVisible(false);
		this.buttonView.setText("<html>培训开始</html>");
		this.buttonView.setEnabled(false);
		this.buttonView.setVisible(false);
		this.buttonList.setText("<html>未完成<BR>清单</html>");
		this.buttonList.setBounds(buttonView.getX(), buttonView.getY() + buttonView.getHeight() + rim,
				buttonView.getWidth(), buttonView.getHeight());
		this.add(buttonList);
		this.buttonList.setVisible(false);

		this.buttonCancel.setEnabled(false);
		this.buttonCancel.setVisible(false);
		this.buttonCancel.setText("已离职");
		this.isCellEditable = false;

		double colRate=0.4;
		scp01.setBounds(rim, scp01.getY(),
				 (int) (WIDTH * colRate), (int)(HEIGHT*0.4));
		scp02.setBounds((int) (WIDTH * colRate + rim), scp01.getY(),
				(int) (this.buttonSearch.getX() - 2 * rim - WIDTH * colRate), scp01.getHeight());
		this.add(scp02);
		scp02.getViewport().add(tab02);
		scp03.setBounds(scp01.getX(), scp01.getY()+scp01.getHeight(),
				(int) (this.buttonSearch.getX() - scp01.getX()-rim), 
				HEIGHT-2*rim-scp01.getY()-scp01.getHeight());
		this.add(scp03);
		scp03.getViewport().add(tab03);
	}
}
